<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <!-- Allow web developers to add meta-data info to their pages for the server to use -->
  <title></title>
  <!--script type="text/javascript" src="http://localhost.classIV.js"-->
  <script type="text/javascript">
    var classiv = function() 
    {
      isSecureProtocol = function()
      {
        //do not let the system work in a secure https area,
        //as a measure to not trespass over the user's trust 
        if (location.protocol == "https:") 
        {
          return true
        }
        return false
      }    
      
      cookies = {}
      cookies.set = function (name,value,expires, options) 
      {   
        if (options==undefined) 
        { 
          options = {}; 
        }   
        if ( expires ) 
        {      
          var expires_date = new Date();      
          expires_date.setDate(expires_date.getDate() + expires)   
        }   
        document.cookie = name+'='+escape( value ) + ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + ( ( options.path ) ? ';path=' + options.path : '' ) +  ( ( options.domain ) ? ';domain=' + options.domain : '' ) +  ( ( options.secure ) ? ';secure' : '' );
      }
      
      cookies.get = function ( name ) 
      {        
        var start = document.cookie.indexOf( name + "=" );        
        var len = start + name.length + 1;        
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
        {                
          return null;        
        }        
        if ( start == -1 ) return null;        
        var end = document.cookie.indexOf( ';', len );        
        if ( end == -1 ) end = document.cookie.length;        
        return unescape( document.cookie.substring( len, end ) );
      }
      
      cookies.remove = function ( name, path, domain ) 
      {   
        if ( cookies.get( name ) ) document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') +      ( ( domain ) ? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
      }
      
      cookies.allowed = function() 
      {   
        cookies.set('checkCookie', 'test', 1);   
        if (cookies.get('checkCookie')) 
        {      
          cookies.remove('checkCookie');      
          return true;   
        }   
        return false;
      }
      
      //classIV only works in non-secure environments and with cookies on
      if (isSecureProtocol()) //secure https
      {
        alert("classIV won't load under a https (secure) protocol") 
        return null
      }

      if (cookies.allowed() == false)
      {
        alert("classIV won't load without cookie support") 
        return null
      }
       
      cIV = {}
      //Server address
      cIV.server  = "http://localhost/classIVserver.php"
      //cIV.server  = "http://localhost/test.js"
      //User hold the id of the local user
      cIV.user = {}
      //permanent/public user key
      cIV.user.guid = 0     
      //temporary/secret user key
      //Get token from cookies
      cookies.remove("classIVusertoken")
      cookies.set("classIVusertoken","123456",0,{"path":"/clientonly"})
      var token = cookies.get("classIVusertoken/clientonly")
      alert(token)
      //if (token == null)
      //{
      //  cookies.set("classIVusertoken","123456")
      //  token = cookies.get("classIVusertoken")
      //}
      cIV.user.token = false//token;


      //Connection encapsulates all communications between client and server 
      cIV.connection = {}
      
      getSendElement = function()
      {
        var i=null; 
        var scripts = document.getElementsByTagName('script');
        for (i in scripts)
        {
           if (scripts[i].id == 'classIVsend')
           {
             return scripts[i]
           }  
        }
        return  null
      }
      
      parseData = function(data)
      {
        var s=''
        if (data == null)
        {
          return s
        }
        //u = username
        //p = password
        //x = logoff
        //l = leave/exit
        //m = move action
        //o = other action
        if (data.user != null) 
        {
          s = s+"&u="+data.user
        }
        if (data.password != null)
        {
          s = s+"&p="+data.password
        }
        if (data.logoff != null)
        {
          s = s+"&x=1"
        }
        if (data.leave != null)
        {
          s = s+"&l=1"
        }        
        return s
      }


      cIV.connection.send = function(data)
      {
        var oldScript = getSendElement()
        
        var newScript = document.createElement('script');      
        newScript.type = 'text/javascript';
        newScript.id = 'classIVsend';      
        newScript.src = cIV.server+"?"+(cIV.user.token ? 't='+cIV.user.token : '')+parseData(data)
  
        var head = document.getElementsByTagName('head')[0];           
  
        if (oldScript == null)
        {
          head.appendChild(newScript)
        }
        else
        {
          //head.replaceChild(newScript,oldScript)
          head.removeChild(oldScript)
          head.appendChild(newScript)
        }
        //document.theForm.submit();
      }
      
      cIV.connection.request = function(what)
      {
        var headID = document.getElementsByTagName("head")[0];           
        var newScript = document.createElement('script');      
        newScript.type = 'text/javascript';      
        newScript.src = what;  
        headID.appendChild(newScript);
      }

      cIV.connection.update = function()
      {
        //request area information
      }      
      
      cIV.connection.login = function(user,password)
      {
        cIV.connection.send({ 'user': user , 'password' : password})
      }
      cIV.connection.logoff = function()
      {
        cIV.connection.send({ 'logoff': true })
      }

      cIV.onbeforeunload = function () 
      {
         cIV.connection.send({ 'leave': true })
         alert("unload")
      }

      cIV.frame = 0
      cIV.main = function()
      {
        cIV.frame = cIV.frame + 1
      }
      cIV.tick = function()
      {
        cIV.main
        cIV.framecallback=setTimeout("cIV.tick()",60); //16fps
      }
      
            
      return cIV
    }()
    append = function(prev,extra) 
    {
      return function(){
        prev()
        extra()
      }
    }
    
    window.onbeforeunload = append(window.onbeforeunload,classiv.onbeforeunload)

  </script>
  </head>
  <body>
    ok
    <form action="http://localhost/classIVserver.php" name='theForm' method='POST'>
        <input type='hidden' name='someField' value='42'>
        <input type='hidden' name='anotherField' value='1337'>
    </form>
    <form>
    <input type="button" value="ok" onMouseDown="classiv.connection.send()">
    </form>
    <a href="javascript:(function(){var s=document.createElement('script');s.charset='UTF-8';s.src=' http://ma.gnolia.com/meta/magframe';document.body.appendChild(s)})();"> Magnolia </a>
  </body>
  <!-- these go in a header below the body --> 
  <head>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 1970 00:00:00 GMT">
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
   </head>  
</html>
